package com.youyicloud.api;

import com.youyicloud.service.WechatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("wechat")
public class WechatApi {
	
	@Autowired
	private WechatService wechatService;

	@RequestMapping("getAccessToken/{appId}/{appSecret}")
	public String getAccessToken(@PathVariable("appId") String appId,@PathVariable("appSecret") String appSecret) {
		String accessToken = wechatService.findNewWechat(appId, appSecret).getAccessTokenValue();
		return accessToken;
	}
	
	@RequestMapping("getJsapiTicket/{appId}/{appSecret}")
	public String getJsapiTicket(@PathVariable("appId") String appId,@PathVariable("appSecret") String appSecret) {
		String jsapiTicketValue = wechatService.findNewWechat(appId, appSecret).getJsapiTicketValue();
		return jsapiTicketValue;
	}
	
	@RequestMapping("updateWechatInfo")
	public String generateAccessToken() {
		wechatService.updateWechatInfo();
		return "生成accesstoken和jsapiTicket成功!";
	}


	@RequestMapping("getCode")
	public void getCode(String appId,String redirectUri,String scope,String state){
		wechatService.getCode(appId,redirectUri,scope,state);
	}
}
